// 添加路由的操作
import { constantRoutes, asyncRoutes } from "@/router"
const state = {
    routes: constantRoutes //当前用户可以访问的所有路由 默认是静态路由可以访问
}
const mutations = {
    // 修改state  添加路由的操作 
    setRoutes(state, newRoutes) {
        state.routes = [...constantRoutes, ...newRoutes]
    },

}
const actions = {
    // 筛选出的用户的动态路由权限 menus是用户信息返回的权限 数组
    // 跟asyncRoutes动态路由的name做对比满足条件的返回出来 赋值给store
    filterRoutes(context, menus) {
        const routes = [] //筛选出的用户的动态路由权限
        menus.forEach(key => {
            // 数组push数组 要...
            routes.push(...asyncRoutes.filter(item => item.name === key))
        });
        context.commit('setRoutes', routes) //修改state数据
        return routes // store数据是左边菜单栏显示内容 return 供调用者使用 addrouter
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}